﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _025类的继承和类的成员访问控制_2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //RaceCar raceCar = new RaceCar();
            //Console.WriteLine(raceCar.Owner);//全盘继承
            Car car = new Car("随机给值测试");
            Console.WriteLine(car.Owner);
            car.ShowBase();

        }
    }

    class Vehicle
    {
        //此时为带参构造器  若子类不携带参数则无法创建
        public Vehicle(string owner)
        {
            this.Owner = owner;
        }
        public string Owner { get; set; }
    }

    class Car : Vehicle
    {
        //public Car()
        //{
        //    //此时Owner字段父类子类指向同一地址  所以这里是把Owner值篡改了
        //    this.Owner = "Car Owner";
        //}

        /*
         以下为解决方法
         */

        //继承父类带参的类 
        //public Car():base("先随便给值再修改") 
        //{
        //    this.Owner = "Car Owner";
        //}

        public Car(string owner) : base(owner)
        {

        }

        public void ShowBase()
        {
            Console.WriteLine(base.Owner);
        }
    }

    //class RaceCar : Car
    //{


    //}

}
